import java.awt.image.BufferedImage;

public class Bee extends Flyer{

    //属性
    private boolean turnright;//true：往右走  false：往左走
    private int level;//leve == 1 attack+1    level == 2 血量+1    level == 3 弹道数+1
    private int speed_x,speed_y;
    private int turn_time;
    private int index = 0;
    //构造器

    public Bee(int x,int level) {
        super(60*level/3,50*level/3,x+60*level/3>StaticNumber.WINWID?x-60*level/3:x,-50*level/3,25);
        turnright = StaticNumber.WINWID - getX()>getX()?true:false;
        this.speed_x = (int)(Math.random()*StaticNumber.BEE_MAX_SPEEDX)+StaticNumber.BEE_MIN_SPEEDX;
        this.speed_y = (int)(Math.random()*StaticNumber.BEE_MAX_SPEEDY)+StaticNumber.BEE_MIN_SPEEDY;
        this.turn_time = PlayPanel.getTime()+StaticNumber.BEE_TURN_TIME;
        this.level = level;
    }


    //方法

    @Override
    void Move() {
        if (getX()+getWidth()>StaticNumber.WINWID||getX()<0) turnright = !turnright;
        if (PlayPanel.getTime()%getSpeed_y()==0){
            setY(getY()+1);
        }
        if (PlayPanel.getTime()%getSpeed_x()==0){
            if (turnright) setX(getX()+1);
            else setX(getX()-1);
        }
    }

    @Override
    BufferedImage getImage() {
        if (turn_time<PlayPanel.getTime()){
            index++;
            turn_time = PlayPanel.getTime()+StaticNumber.BEE_TURN_TIME;
        }
        if (index<5) return Game.beeimg[index];
        else return null;
    }


    public int getSpeed_x() {
        return speed_x;
    }

    public void setSpeed_x(int speed_x) {
        this.speed_x = speed_x;
    }

    public int getSpeed_y() {
        return speed_y;
    }

    public void setSpeed_y(int speed_y) {
        this.speed_y = speed_y;
    }

    public int getLevel() {
        return level;
    }
}

